//header-nav
const show = document.querySelectorAll('.header-nav a')
const header_bottom = document.querySelector('.header-bottom')
//search
const search = document.getElementById('search')
const search_input = document.querySelector('.search-input')
//购物车
const gwc = document.querySelector('.gwc')
const gwcc = document.querySelector('.gwcc')
//banner-left nav
const menus = document.querySelectorAll('.banner .left-nav ul li a')
const list = document.querySelectorAll('.banner .list')
//banner
const mainAs = document.querySelectorAll('.bg-img a')
const banner = document.querySelector('.banner')
const prevBtn = document.querySelector('.banner .left-arr')
const nextBtn = document.querySelector('.banner .right-arr')


let initNum = 0
let banner_time = setInterval(function () {
    for (let i = 0; i < mainAs.length; i++) {
        mainAs[initNum].classList.remove('show')
    }
    initNum += 1
    if (initNum >= mainAs.length) {
        initNum = 0
    }
    console.log(initNum)
    mainAs[initNum].classList.add('show')
}, 5000)

banner.onmouseenter = function () {
    clearInterval(banner_time)
}

banner.onmouseleave = function () {
    banner_time = setInterval(function () {
        for (let i = 0; i < mainAs.length; i++) {
            mainAs[initNum].classList.remove('show')
        }

        initNum += 1
        if (initNum >= mainAs.length) {
            initNum = 0
        }
        console.log(initNum)
        mainAs[initNum].classList.add('show')
    }, 5000)
}

prevBtn.onclick = function () {
    for (let i = 0; i < mainAs.length; i++) {
        mainAs[initNum].classList.remove('show')
    }

    initNum -= 1
    if (initNum < 0) {
        initNum = mainAs.length - 1
    }
    console.log(initNum)
    mainAs[initNum].classList.add('show')
}

nextBtn.onclick = function () {
    for (let i = 0; i < mainAs.length; i++) {
        mainAs[initNum].classList.remove('show')
    }

    initNum += 1
    if (initNum > mainAs.length - 1) {
        initNum = 0
    }
    console.log(initNum)
    mainAs[initNum].classList.add('show')
}




gwc.onmouseover = function () {
    gwcc.style.display = 'block'
}
gwc.onmouseout = function () {
    gwcc.style.display = 'none'
}
gwcc.onmouseover = function () {
    gwcc.style.display = 'block'
}
gwcc.onmouseout = function () {
    gwcc.style.display = 'none'
}

for (let i = 0; i < menus.length; i++){
    menus[i].onmouseenter = function () {
        list[i].style.display = 'block'
    }
    menus[i].onmouseleave = function () {
        list[i].style.display = 'none'
    }
    list[i].onmouseenter = function () {
        list[i].style.display = 'block'
    }
    list[i].onmouseleave = function () {
        list[i].style.display = 'none'
    }
}



for (let i = 0; i < show.length - 2; i++) {
    show[i].onmouseenter = function () {
        console.log(123)
        header_bottom.style.display = 'block'
    }
    show[i].onmouseleave = function () {
        header_bottom.style.display = 'none'
    }
    header_bottom.onmouseenter = function () {
        header_bottom.style.display = 'block'
    }
    header_bottom.onmouseleave = function () {
        header_bottom.style.display = 'none'
    }
}




search.onclick = function () {
    console.log(123)
    if (search_input.style.display === 'block'){
        search_input.style.display = 'none'
        search.style.border = '1px solid #e0e0e0'
    }else {
        search_input.style.display = 'block'
        search.style.border = '1px solid #ff6700'
    }
}


